﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyBlog.DataEntity;

namespace MyBlog.DataAccess
{
    internal class ArticleMap : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<Tbl_Article>
    {
        public ArticleMap()
        {
            this.HasMany(e => e.Tbl_ArticleComment)
                 .WithRequired(e => e.Tbl_Article)
                 .HasForeignKey(e => e.ArticleId)
                 .WillCascadeOnDelete(false);

            //文章和文章类别是多对多关系
            this.HasMany(b => b.Tbl_Category)
                .WithMany(c => c.Tbl_Article)
                .Map(m => 
                {
                    m.MapLeftKey("ArticleID");
                    m.MapRightKey("CategoryID");
                    m.ToTable("Tbl_ArticleCategory");
                });

            this.HasMany(b => b.Tbl_Tag)
                .WithMany(c => c.Tbl_Article)
                .Map(m =>
                {
                    m.MapLeftKey("ArticleID");
                    m.MapRightKey("TagID");
                    m.ToTable("Tbl_ArticleTag");
                });
        }
    }
}
